package cn.campus.controller;

import java.util.UUID;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;

import cn.campus.pojo.Forum_reply;
import cn.campus.pojo.Forum_replyAndUser;
import cn.campus.pojo.User;
import cn.campus.service.ForumReplyService;

@Controller
@RequestMapping("/forumReply")
public class ForumReplyController {

	@Resource
	private ForumReplyService forumReplyService;

	@RequestMapping("addForumReply")
	@ResponseBody
	public String addForumReply(Forum_reply forum_reply,HttpSession httpSession){
		User user = (User) httpSession.getAttribute("user");
		if(user==null){
			return JSON.toJSONString("请先登录");
		}
		String forum_reply_id = UUID.randomUUID().toString();
		forum_reply.setForum_reply_id(forum_reply_id);
		forum_reply.setReplyer_id(user.getUser_id());
		int i = forumReplyService.addForumReply(forum_reply);
		if(i>=0){
			return JSON.toJSONString("回复成功");
		}
		return JSON.toJSONString("回复失败");
	}
	@RequestMapping("findAllForumReply")
	@ResponseBody
	public String findAllForumReply(int currentPage,int count){
		Forum_replyAndUser forum_replyAndUser = forumReplyService.findAllForumReplys(currentPage, count);
		return JSON.toJSONString(forum_replyAndUser);
	}
}
